import { http } from "@/utils/http";
import type { PureHttpRequestConfig } from "@/utils/http/types";

export function downLoadByUrl(
  url: string,
  fileName: string,
  requestConfig: PureHttpRequestConfig
) {
  http.request<string>("get", url, {}, requestConfig).then(response => {
    // 删除\x00等不可见字符
    response = response.replace(/\x00/g, "");
    const blob = new Blob([response], { type: "plain/text" });
    const url = window.URL.createObjectURL(blob); // 创建一个指向该blob的URL
    const a = document.createElement("a");
    a.style.display = "none";
    a.href = url;
    a.download = fileName;
    document.body.appendChild(a);
    a.click();
    window.URL.revokeObjectURL(url); // 释放URL对象
  });
}
